﻿using System.Windows;

namespace MyTodo.Views
{
    /// <summary>
    /// Interaction logic for MainView.xaml
    /// </summary>
    public partial class MainView : Window
    {
        public MainView()
        {
            InitializeComponent();

            listTodo.SelectionChanged += (s, e) =>
            {
                draweHost.IsLeftDrawerOpen = false;
            };

            btnMin.Click += (s, e) =>
            {
                this.WindowState = WindowState.Minimized;
            };

            btnMax.Click += (s, e) =>
            {
                if (this.WindowState!= WindowState.Maximized)
                {
                    this.WindowState = WindowState.Maximized;
                }
                else
                {
                    this.WindowState = WindowState.Normal;
                }
            };

            btnClose.Click += (s, e) =>
            {
                if (MessageBox.Show("确认关闭吗？", "提示", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                {
                    Application.Current.Shutdown();
                }
            };

            HeaderBar.MouseMove += HeaderBar_MouseMove;
            HeaderBar.MouseDoubleClick += HeaderBar_MouseDoubleClick;
        }

        private void HeaderBar_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            if (this.WindowState != WindowState.Maximized)
            {
                this.WindowState = WindowState.Maximized;
            }
            else
            {
                this.WindowState = WindowState.Normal;
            }
        }

        private void HeaderBar_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
        {
            if (e.LeftButton== System.Windows.Input.MouseButtonState.Pressed)
            {
                this.DragMove();
            }
        }
    }
}
